package view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import model.Conference;
import model.FileParser;
import model.Role;
import model.State;

/**
 * Displays the non-role specific information in the main GUI view.
 * @author Sarah George
 * @version Autumn 2012
 */
@SuppressWarnings("serial")
public class UserPanel extends JPanel {
	
	/**
	 * The current state of the system.
	 */
	private State my_state;
	
	/**
	 * Constructor for the general user panel containing information 
	 * pertinent to the current conference.
	 * @param the_state the current state of the system.
	 */
	public UserPanel(State the_state) {
		super();
		setPreferredSize(new Dimension(400, 300));
		setBackground(Color.CYAN);
		my_state = the_state;
		setup();
	}

	/**
	 * Sets up the Panel that is the same for all users.
	 */
	public void setup() {
		GridLayout exp_layout = new GridLayout(0,1);
		Conference curr_conf = my_state.getConference();
		this.setLayout(exp_layout);
		this.add(new JLabel("Welcome! "+ my_state.getUser()+""));
		this.add(new JLabel("Viewing: "+ curr_conf.getConfName()+""));
		this.add(new JLabel("Location: " + curr_conf.getLocation()));
		this.add(new JLabel("StartDate: " + curr_conf.getStartDate()));
		this.add(new JLabel("EndDate: " + curr_conf.getEndDate()));
		this.add(new JLabel("Submission Deadline: " + curr_conf.getSubmissionDL()));
		this.add(new JLabel("Review Deadline: "+ curr_conf.getReviewDL()));
		this.add(new JLabel("Recommendation Deadline: " + curr_conf.getRecommendationDL()));
		this.add(new JLabel("Decision Deadline: " + curr_conf.getDecisionDL()));
		if (my_state.getRole() == Role.PC)
			this.add(new JButton(new NewConfAction()));
	}
	
	/**
	 * Class to add a new conference.
	 */
	private class NewConfAction extends AbstractAction
	{
		/**
		 * Constructor for a new Conference Action.
		 */
		public NewConfAction()
		{
			super("Add New Conference...");
		    putValue(Action.MNEMONIC_KEY, KeyEvent.VK_N);
		    putValue(Action.SELECTED_KEY, true);
		}
		
		/**
		 * Method to create a new conference GUI.
		 * @param arg0 the action event that triggers the method.
		 */
		@Override
		public void actionPerformed(ActionEvent arg0) {
			JFrame new_conf_frame = new JFrame("Add New Conference");
			NewConfPanel ncp = new NewConfPanel(my_state, new_conf_frame);
			
			new_conf_frame.add(ncp,BorderLayout.CENTER);
			new_conf_frame.setResizable(true); 
			new_conf_frame.pack();
			new_conf_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   
			new_conf_frame.setLocationRelativeTo(null);
			new_conf_frame.setVisible(true);
		}

	}//End class new conf action.
}//End class user panel.